package com.nice.demo.test;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

import androidx.core.widget.NestedScrollView;

/**
 * author : jc
 * date   : 2020/3/13
 * desc   :
 * version: 1.0
 */
public class ZuotiHandNestedScrollView extends NestedScrollView {
    private static final String TAG = "ZuotiHandScrollView";
    public static final int TAG_TOUCH = 0;
    public static final int TAG_PEN = 1;
    private ZuotiHandNestedScrollView.HandScrollViewCallback callback;

    public ZuotiHandNestedScrollView.HandScrollViewCallback getCallback() {
        return this.callback;
    }

    public void setCallback(ZuotiHandNestedScrollView.HandScrollViewCallback callback) {
        this.callback = callback;
    }

    public ZuotiHandNestedScrollView(Context context) {
        super(context);
    }

    public ZuotiHandNestedScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public ZuotiHandNestedScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return super.dispatchTouchEvent(ev);
    }

    @SuppressLint({"NewApi"})
    public boolean onInterceptTouchEvent(MotionEvent ev) {
//        return false;
        int toolType = ev.getToolType(0);
        if (toolType == MotionEvent.TOOL_TYPE_STYLUS) {//手写笔触摸
            Log.e("jc", "onInterceptTouchEvent() >>> toolType == TOOL_TYPE_STYLUS");

            if (this.callback != null) {
                this.callback.back(1, (Object) null);
            }
            return false;
        } else {
            if (this.callback != null) {
                this.callback.back(0, (Object) null);
            }
            return super.onInterceptTouchEvent(ev);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return super.onTouchEvent(ev);

    }

    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        Log.e("jc", "changed = [" + changed + "], l = [" + l + "], t = [" + t + "], r = [" + r + "], b = [" + b + "]");

    }

    public interface HandScrollViewCallback {
        void back(int var1, Object var2);
    }
}
